package com.atos.smp.actions;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.SessionScoped;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

import org.primefaces.component.confirmdialog.ConfirmDialog;
import org.primefaces.component.dialog.Dialog;
import org.primefaces.component.inputtext.InputText;

import net.codeissue.web.common.ServiceFinder;

import com.atos.smp.beans.Tool;
import com.atos.smp.business.ToolManager;
import com.atos.smp.business.impl.ToolManagerImpl;
import com.atos.smp.dao.ToolDao;

@ManagedBean
@SessionScoped
public class ToolsBean implements Serializable {

	private ToolManager ToolManager;
	private List<Tool> Tools;
	private Tool selectedTool;
	private Tool newTool;
	private String das;
	private boolean update= false;

	public ToolsBean() {
		ToolManager = Action.getToolManager();
		Tools = ToolManager.findAllTools();
		newTool = new Tool();
		selectedTool = new Tool();
	}

	public List<Tool> getTools() {
		if(update)
			Tools = ToolManager.findAllTools();
		update = false;
		return Tools;
	}

	public void setTools(List<Tool> Tools) {
		this.Tools = Tools;
	}

	public Tool getSelectedTool() {
		return selectedTool;
	}

	public void setSelectedTool(Tool selectedTool) {
		this.selectedTool = selectedTool;

	}

	public String addTool() {
		ToolManager.save(newTool);
		newTool = new Tool();
		update = true;
		return "";
	}
	public String updateTool() {
		ToolManager.update(selectedTool);
		update = true;
		return "updateSuccess";
	}

	public void deleteTool(Tool item) {
		if (item != null) {
			ToolManager.delete(item);
		}
		update=true;
	}


	public Tool getNewTool() {
		return newTool;
	}

	public void setNewTool(Tool newTool) {
		this.newTool = newTool;
	}

	public boolean isUpdate() {
		return update;
	}

	public void setUpdate(boolean update) {
		this.update = update;
	}
}
